package com.beans;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import model.Projection;

import com.services.ProjectionsService;

@ManagedBean(name = "projectionsBean")
@RequestScoped
public class ProjectionsBean implements Serializable {

	@EJB
	ProjectionsService service;

	@ManagedProperty(value = "#{projectionBean}")
	private ProjectionBean projectionBean;

	private List<Projection> projections;

	public ProjectionsBean() {

	}

	public ProjectionBean getProjectionBean() {
		return projectionBean;
	}

	public void setProjectionBean(ProjectionBean projectionBean) {
		this.projectionBean = projectionBean;
	}

	public List<Projection> getProjections() {
		this.projections = service.getAllProjections();
		return projections;
	}

	public void setProjections(List<Projection> projections) {
		this.projections = projections;
	}

	public List<Projection> getProjectionsForCinema(int cinemaId) {
		return service.getAllCinemaProjections(cinemaId);
	}
	
	public List<Projection> getProjectionsForMovie(int movieId) {
		return service.getAllMovieProjections(movieId);
	}

	public void navigateToProjectionPage(int projectionId) throws IOException {
		this.projectionBean.setProjection(service
				.getProjectionById(projectionId));

		FacesContext.getCurrentInstance().getExternalContext()
				.redirect("projection.seam");
	}

}